package com.itheima.tliassystem.controller;


import entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.itheima.tliassystem.uile.AliOSSUtils;


import java.io.IOException;

@RestController
@RequestMapping("/upload")
public class FileUploadController {
@Autowired
AliOSSUtils aliOSSUtils;
    @PostMapping
    public Result upload(MultipartFile image) throws IOException {

//        String originalFilename = image.getOriginalFilename();
//        String substring = originalFilename.substring(originalFilename.lastIndexOf("."));
//        String s = UUID.randomUUID().toString() + substring;
//
//        OSS ossClient = new OSSClientBuilder().build("https://oss-cn-nanjing.aliyuncs.com", "LTAI5tNqS9KjQoMYkBb5TzxV","12SCkNFPLICgP1qgFoMsepMOIyrdnI");
//   ossClient.putObject("tlias-system-bucket-wangle",s,image.getInputStream());
//
//
//        return Result.success("https://tlias-system-bucket-wangle.oss-cn-nanjing.aliyuncs.com/"+s);
        //直接调用工具类方法
        String filepath = aliOSSUtils.upload(image);
        return Result.success(filepath);


    }

}
